<template>
  <PageWrapper>
    <BasicTable class="page-search-table" @register="registerTable" />
    <Dialog @register="registerModel" @success="submitSuccess" />
  </PageWrapper>
</template>
<script lang="ts">
  import { defineComponent } from 'vue';
  import { BasicTable, useTable } from '/@/components/Table';
  import { PageWrapper } from '/@/components/Page';
  import { useModal } from '/@/components/Modal';
  import { tableConfig } from './tableData';
  import Dialog from './dialog.vue';
  import { useMessage } from '/@/hooks/web/useMessage';
  export default defineComponent({
    components: {
      PageWrapper,
      BasicTable,
      Dialog,
    },
    setup(_) {
      const { createMessage } = useMessage();
      const [registerModel, { openModal: openModal }] = useModal();
      const [registerTable, { reload }] = useTable(tableConfig);
      function openAdd() {
        openModal(true, {
          isUpdate: false,
        });
      }
      function submitSuccess(e) {
        reload();
        createMessage.success(e.isUpdate ? '修改成功' : '添加成功');
      }
      function openEdit(rowdata: Recordable) {
        openModal(true, {
          rowdata,
          isUpdate: true,
        });
      }
      return {
        registerModel,
        openModal,
        registerTable,
        submitSuccess,
        openAdd,
        openEdit,
      };
    },
  });
</script>
